package com.study_platform.controller;


import com.study_platform.entity.Question;
import com.study_platform.service.QuestionService;
import com.study_platform.util.VO.GradeVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author auto
 * @since 2023-04-11
 */
@RestController
@RequestMapping("/study_platform")
public class ClassificationController {

    @Resource
    private QuestionService questionService;

    @GetMapping("/grade/getgrade/")
    public List<String> getGrade(){
        Set<String> set = new HashSet<>();
        List<Question> questions = questionService.list();
        for(Question question : questions){
            set.add(question.getGrade().toString());
        }
        List<String> grades = new ArrayList<>();
        for(String s : set){
            grades.add(s);
        }
        return grades;
    }

    @GetMapping("/point/getpoint/")
    public List<String> getPoint(@RequestParam String grade){
        System.out.println(grade);
        List<String> points = new ArrayList<>();
        List<Question> questions = questionService.lambdaQuery()
                .eq(Question::getGrade, grade)
                .list();

        Set<String> set = new HashSet<>();
        for(Question question : questions){
            if (!set.contains(question.getPoint())){
                set.add(question.getPoint());
                points.add(question.getPoint());
            }
        }

        return points;
    }

    @GetMapping("/point/getallpoint/")
    public List<String> getAllPoint(){
        List<Question> questions = questionService.lambdaQuery()
                .groupBy(Question::getPoint)
                .list();
        Set<String> set = new HashSet<>();
        List<String> points = new ArrayList<>();
        for (Question question : questions){
            if (!set.contains(question.getPoint())){
                set.add(question.getPoint());
                points.add(question.getPoint());
            }
        }

        return points;
    }
}

